package org.lex.utils.logging;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;

import org.lex.utils.text.Chars;


/**
 * һ���ǳ��򵥵�LogRecord Formatter ֻ����LogRecord.getMessage()���֣�����������Ϣ
 * 
 * @author Lex
 */
public class TinyFormatter extends Formatter {
	private String lineSeparator = Chars.newline;
	private StringBuffer buffer = new StringBuffer();

	public synchronized String format(LogRecord record) {
		buffer.setLength(0);
		buffer.append("[").append(record.getLevel().getName()).append("] ");
		buffer.append(record.getMessage());
		buffer.append(lineSeparator);
		if (record.getThrown() != null) {
			try {
				StringWriter sw = new StringWriter();
				PrintWriter pw = new PrintWriter(sw);
				record.getThrown().printStackTrace(pw);
				pw.close();
				buffer.append(sw.toString());
			} catch (Exception ex) {
			}
		}
		return buffer.toString();
	}
}
